<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        function *enumerable(msg){
            //console.log(msg)
            try {
                var msg1 = yield 1;
            } catch (error) {
                console.log(error)
            }            
            //console.log(msg1)
            var msg2 = yield 2
            try{
                var msg3 = yield 3;
                //console.log('ok')
            }
            catch(e){
                //console.log(e)
            }
            //console.log(msg2 + ' over')
            //console.log(yield + 1)
        }
        var enumerator = enumerable(5)
        var ret = enumerator.next();
        ret = enumerator.throw(new Error('qwewqe'));
        console.log(ret)
        // var ret = enumerator.next(11) // 控制台显示 hello，ret的值{value:'hello after',done:false}
        // ret =  enumerator.next('world') // 控制台显示 world，ret的值{value:'world after',done:false}
        // ret = enumerator.next('game') // 控制台显示game，ret的值{value:'game after',done:false}
        
        // // 抛出异常信息
        // ret = enumerator.throw(new Error('test')) // 控制台显示new Error('test')信息，然后显示game over。ret的值为{done:true}
        // ret = enumerator.next({name: 'lhr'})
        // for...of语句
        //enumerator = enumerable('hello')
        //for(retqweweq of enumerator)
        //console.log(JSON.stringify(retqweweq));
    </script>
</body>
</html>